import { mapGetters } from 'vuex'
// 封装角标相关的混入逻辑
export default {
  computed: {
    ...mapGetters('cart', ['totalCount']),
  },
  watch: {
    totalCount: {
      immediate: true,
      handler(newVal) {
        if (newVal > 0) {
          uni.setTabBarBadge({
            index: 2,
            text: '' + newVal, // 必须字符串
          })
        } else {
          uni.removeTabBarBadge({
            index: 2,
          })
        }
      },
    },
  },
  // 获取某个模块的state
  // $store.state.cart.xxx   ...mapState('cart', ['xxxx'])
  // 获取某个模块的getters
  // $store.getters['cart/xxx']  ...mapGetters('cart', ['xxx'])
  onShow() {
    uni.setTabBarBadge({
      index: 2,
      text: '' + this.totalCount,
    })
  },
}
